# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user              vagrant;
worker_processes  <%= @processorcount %>;

worker_rlimit_nofile    4096;

error_log  /var/log/nginx/error.log warn;

pid        /var/run/nginx.pid;


events {
    use epoll;
    worker_connections  2048;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    underscores_in_headers on;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    client_max_body_size  128M;

# avoid some operation time out , like download something ,tiff,etc.	
    fastcgi_connect_timeout 75;
    fastcgi_read_timeout 600;
    fastcgi_send_timeout 600;

    fastcgi_buffers     8   4K;
    fastcgi_buffer_size 4K;

# gzip compression
    gzip  on;
    gzip_min_length  	50000;
    gzip_buffers 16 64k;
    gzip_http_version 1.1;
    gzip_comp_level 9;
    gzip_types text/plain application/javascript text/css application/xml application/json;
    gzip_vary on;

    add_header  Cache-Control   max-age=604800;

    proxy_connect_timeout 600;
    proxy_send_timeout 600;
    proxy_read_timeout 600;
    proxy_buffer_size 16k;
    proxy_buffering off;
    proxy_buffers 4 32k;
    proxy_busy_buffers_size 64k;
    proxy_temp_file_write_size 64k;

    #refer:https://my.oschina.net/xiehongfei/blog/515166

#    geo $whiteiplist {
#    default 1;
#    192.168.65.1 0;
#    54.85.62.221 0;
#    58.30.71.34 0;
#    172.18.0.1 0;
#    }

    map_hash_bucket_size 128;

    map $http_x_connectedpdf_ua $limit {
    default "";
    "al(en-US);cv(1.0.0.0);an(ConnectedPDF windows Service);av()" $binary_remote_addr;
    }

    map $http_x_connectedpdf_ua $limit {
    default "";
    "al(en-US);cv(2.0.0.0);an(Foxit MobilePDF for Android);av(5.3.0.1309)" $binary_remote_addr;
    }

    map $http_x_connectedpdf_ua $limit {
    default "";
    "al(zh-CN);cv(2.0.0.0);an(Foxit MobilePDF for Android);av(5.3.0.1309)" $binary_remote_addr;
    }

     map $http_x_connectedpdf_ua $limit {
     default "";
     "al(es-US);cv(2.0.0.0);an(Foxit MobilePDF for Android);av(5.3.0.1309)" $binary_remote_addr;
     }

    map $request_method $post_limit {
    default "";
    POST $limit;
    }

    limit_req_zone $post_limit zone=one:10m rate=4r/m;

   include vhost/common.conf;
   include vhost/vhost-local.conf;
   include vhost/cpdf20.conf;
   include vhost/phantom-online.conf;
   # refer:demo2 storage-demo2.connectedpdf.com
   include vhost/storage-demo2.conf;

}
